#
# Login call.  Expects input "user" and "pass" in the form
#

import cgi
import os
import UserUtils
from django.utils import simplejson as json

print "Content-type: text/html\n\n";
#print "hi";
#print "<br>"

form = cgi.FieldStorage()
#for key in form:
#  print "<p>%s : %s" % (key, form[key].value)

if ("user" in form) & ("pass" in form) :
  u = UserUtils.GALogin(form['user'].value, form['pass'].value)
  print json.dumps( {'user' : u.username, 'ticket' : u.ticket} )
else:
  print json.dumps( {'user' : None, 'ticket' : None} )

#if 'HTTP_COOKIE' in os.environ:
#  cookies = os.environ['HTTP_COOKIE']
#  cookies = cookies.split('; ')

#for cookie in cookies:
#   cookie = cookie.split('=')
#   print "<br>%s - %s <br>" % (cookie[0] , cookie[1])


#print "got user " + str(u.screenname) + " with ticket " + str(u.ticket) + "<br/>"

#vu = UserUtils.GAValidateTicket(u.ticket)
#print "got validated user " + str(vu.screenname) + " with ticket " + str(vu.ticket) + " and timestamp " + str(vu.timestamp) + "<br/>"


